home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ahoy 1984 January to June
/
Ahoy_Magazine_84-Jan-Jun_1984_Double_L.d64
/
commodares #5-1
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-10-26
|
540b
|
16 lines
0 rem--ahoy!--may issue--commodares #5--prog page 91
1 rem << problem 4-1 : squared sum >>
2 rem - find numbers equal to the square of the sum of their digits
5 for j=1 to 100
10 sum=0 : rem initial sum of digits
15 jj=j*j : rem jj is a square
20 j$=str$(jj) :rem convert jj to a string variable j$
25 rem -- lines 30 - 60 take each digit of j$ and add its value to sum ---
30 for d=2 to len(j$)
40 v=val(mid$(j$,d,1))
50 sum=sum+v
60 next d
65 ss=sum*sum : rem > get the square of the sum of the digits
70 if abs(ss-jj)<1e-4 then print jj"is a solution"
80 next j